/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.awt.BorderLayout;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.swing.JRViewer;
import sys.bean.ProdutoBean;
import sys.dao.ProdutoDao;
import sys.utils.LetterUpper;
import sys.utils.Mensagens;
import sys.utils.Utils;
import static sys.utils.Utils.escClose;

/**
 *
 * @author Administrador
 */
public class UIEtiquetas extends javax.swing.JDialog {

    private List<ProdutoBean> listaTabelaPesquisa;
    private final List<ProdutoBean> listaTabelaEtiquetas = new ArrayList<>();

    /**
     * Creates new form NewJDialog
     *
     * @param parent
     * @param modal
     */
    public UIEtiquetas(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        UIManager.put("Table.alternateRowColor", new java.awt.Color(230, 255, 255));
        setLocationRelativeTo(null);
        escClose(this);
        Utils.maximizarDialog(this);
    }

    private void gerarEtiquetas() {

        tabbedPane.setSelectedIndex(1);
        HashMap par = new HashMap();

        JRDataSource jasperSource = new JRBeanCollectionDataSource(listaTabelaEtiquetas);

        jpVisualizarEtiqueta.removeAll();
        jpVisualizarEtiqueta.setLayout(new BorderLayout());
        InputStream dirReport = this.getClass().getClassLoader().getResourceAsStream("sys/report/etiquetas.jasper");

        try {
            JasperPrint jasperPrint = JasperFillManager.fillReport(dirReport, par, jasperSource);

//            String nomeRelatorio = "Relatorio_" + nomeRelatorio() + ".pdf";
//            JasperExportManager.exportReportToPdfFile(jasperPrint, System.getProperty("java.io.tmpdir") + "/" + nomeRelatorio);
//            Runtime.getRuntime().exec("cmd /c start " + System.getProperty("java.io.tmpdir") + "/" + nomeRelatorio);
//            File file = new File(System.getProperty("java.io.tmpdir") + "/" + nomeRelatorio);
//            file.deleteOnExit();
            
            JRViewer jasperViewer = new JRViewer(jasperPrint);
            jpVisualizarEtiqueta.add(jasperViewer);
            jpVisualizarEtiqueta.revalidate();
            jpVisualizarEtiqueta.repaint();
        } catch (JRException ex) {
            Mensagens.msgErro("erro ao gerar cobranca\n" + ex.getMessage());
        }

    }

    private void buscaProduto() {
        final BarraProgresso pb = new BarraProgresso(this);
        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {
                pb.gerarJanela();
                pb.lbDescricao.setText("BUSCANDO, POR FAVOR AGUARDE...");
                atualizaTabelaPesquisa();
                return null;
            }

            @Override
            protected void done() {
                pb.fechar();
            }
        };
        worker.execute();
    }

    public void addProduto() {
        int[] linhas = tabelaPesquisa.getSelectedRows();
        for (int i = 0; i < linhas.length; i++) {
            ProdutoBean produto = new ProdutoBean();

            produto.setCodigo(tabelaPesquisa.getValueAt(linhas[i], 1).toString());
            produto.setDescricao(tabelaPesquisa.getValueAt(linhas[i], 0).toString());
            produto.setCodigoBarras(tabelaPesquisa.getValueAt(linhas[i], 1).toString());

            listaTabelaEtiquetas.add(produto);
        }
    }

    public void removerProduto() {
        listaTabelaEtiquetas.remove(tabelaListaEtiquetas.getSelectedRow());
        atualizaTabelaEtiquetas();
        tabelaListaEtiquetas.requestFocus();
        tabelaListaEtiquetas.changeSelection(0, 1, false, false);
    }

    private void atualizaTabelaEtiquetas() {
        
        DefaultTableModel modelo = (DefaultTableModel) tabelaListaEtiquetas.getModel();
        modelo.setNumRows(0);

        for (ProdutoBean produto : listaTabelaEtiquetas) {
            modelo.addRow(new Object[]{
                produto.getDescricao(), produto.getCodigoBarras()
            });
        }
        DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
        centralizado.setHorizontalAlignment(SwingConstants.CENTER);
        tabelaListaEtiquetas.getColumnModel().getColumn(1).setCellRenderer(centralizado);

    }

    private void atualizaTabelaPesquisa() {
        DefaultTableModel modelo = (DefaultTableModel) tabelaPesquisa.getModel();
        modelo.setNumRows(0);

        try {
            listaTabelaPesquisa = ProdutoDao.listaProdutosSpac(txConsulta());
            for (ProdutoBean produto : listaTabelaPesquisa) {
                modelo.addRow(new Object[]{
                    produto.getDescricao(), produto.getCodigoBarras()
                });
            }
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro\n" + ex.getMessage());
        }
        tabelaPesquisa.requestFocus();
        tabelaPesquisa.changeSelection(0, 2, false, false);

        DefaultTableCellRenderer centralizado = new DefaultTableCellRenderer();
        centralizado.setHorizontalAlignment(SwingConstants.CENTER);
        tabelaPesquisa.getColumnModel().getColumn(1).setCellRenderer(centralizado);

    }

    private boolean validaInfo() {
        boolean v = true;
        String msg = "Selecione pelo menos uma opção de pesquisa.";

        if (jcbPesContenha.isSelected() || jcbPesIncremental.isSelected()) {
        } else {
            v = false;
        }
        if (v == false) {
            Mensagens.msgAtencao(msg);
        }
        return v;
    }

    private String txConsulta() {
        if (jcbPesContenha.isSelected()) {

            String pParte = "";
            String uParte = "";
            String tx = txProduto.getText();

            String[] sql = tx.split(" ");

            int cont = 0;
            for (String conteudoTxproduto : sql) {
                if (cont == 0) {
                    pParte += "WHERE C01DESC LIKE '%" + conteudoTxproduto + "%' ";
                }
                if (cont > 0) {
                    uParte += "AND C01DESC LIKE '%" + conteudoTxproduto + "%' ";
                }
                cont++;
            }
            return pParte + uParte + " AND C01FLAG = 'A' ORDER BY C01DESC";

        } else {
            return "WHERE C01DESC LIKE '" + txProduto.getText() + "%' AND C01FLAG = 'A'";
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        txProduto = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jcbPesIncremental = new javax.swing.JCheckBox();
        jcbPesContenha = new javax.swing.JCheckBox();
        tabbedPane = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        btnMaior = new javax.swing.JButton();
        btnMenor = new javax.swing.JButton();
        btnLimpaTabela = new javax.swing.JButton();
        btnMenor1 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaPesquisa = new javax.swing.JTable();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaListaEtiquetas = new javax.swing.JTable();
        jpVisualizarEtiqueta = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        btnBuscar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("GERAR ETIQUETAS");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OPÇÕES:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        txProduto.setDocument(new LetterUpper());
        txProduto.setBackground(new java.awt.Color(245, 245, 245));
        txProduto.setFont(new java.awt.Font("Calibri", 0, 14)); // NOI18N
        txProduto.setBorder(null);
        txProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txProdutoActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel1.setText("DESCRIÇÃO DO PRODUTO:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txProduto)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(4, 4, 4)
                .addComponent(txProduto, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PESQUISA", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jcbPesIncremental.setBackground(new java.awt.Color(255, 255, 255));
        jcbPesIncremental.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jcbPesIncremental.setText("INCREMENTAL");
        jcbPesIncremental.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPesIncrementalActionPerformed(evt);
            }
        });

        jcbPesContenha.setBackground(new java.awt.Color(255, 255, 255));
        jcbPesContenha.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jcbPesContenha.setSelected(true);
        jcbPesContenha.setText("CONTENHA");
        jcbPesContenha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPesContenhaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jcbPesIncremental)
                .addContainerGap())
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcbPesContenha)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcbPesContenha, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(jcbPesIncremental, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        tabbedPane.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        btnMaior.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        btnMaior.setText("+");
        btnMaior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMaiorActionPerformed(evt);
            }
        });

        btnMenor.setFont(new java.awt.Font("Calibri", 1, 16)); // NOI18N
        btnMenor.setText("-");
        btnMenor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMenorActionPerformed(evt);
            }
        });

        btnLimpaTabela.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        btnLimpaTabela.setText("*");
        btnLimpaTabela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpaTabelaActionPerformed(evt);
            }
        });

        btnMenor1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnMenor1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/print.png"))); // NOI18N
        btnMenor1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMenor1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnMaior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnMenor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnMenor1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(btnLimpaTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(btnMaior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnMenor, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnLimpaTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(btnMenor1)
                .addGap(0, 242, Short.MAX_VALUE))
        );

        tabelaPesquisa.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaPesquisa.setForeground(new java.awt.Color(51, 51, 255));
        tabelaPesquisa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "DESCRIÇÃO", "CODIGO DE BARRAS"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaPesquisa.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaPesquisa.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tabelaPesquisa);
        if (tabelaPesquisa.getColumnModel().getColumnCount() > 0) {
            tabelaPesquisa.getColumnModel().getColumn(0).setPreferredWidth(200);
        }

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        tabelaListaEtiquetas.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        tabelaListaEtiquetas.setForeground(new java.awt.Color(51, 51, 255));
        tabelaListaEtiquetas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "DESCRIÇÃO", "CODIGO DE BARRAS"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaListaEtiquetas.setGridColor(new java.awt.Color(204, 204, 204));
        tabelaListaEtiquetas.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(tabelaListaEtiquetas);
        if (tabelaListaEtiquetas.getColumnModel().getColumnCount() > 0) {
            tabelaListaEtiquetas.getColumnModel().getColumn(0).setPreferredWidth(200);
        }

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(15, 15, 15))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        tabbedPane.addTab("GERAR ETIQUETAS", new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-product.png")), jPanel4); // NOI18N

        javax.swing.GroupLayout jpVisualizarEtiquetaLayout = new javax.swing.GroupLayout(jpVisualizarEtiqueta);
        jpVisualizarEtiqueta.setLayout(jpVisualizarEtiquetaLayout);
        jpVisualizarEtiquetaLayout.setHorizontalGroup(
            jpVisualizarEtiquetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 970, Short.MAX_VALUE)
        );
        jpVisualizarEtiquetaLayout.setVerticalGroup(
            jpVisualizarEtiquetaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 398, Short.MAX_VALUE)
        );

        tabbedPane.addTab("VISUALIZAR ETIQUETAS", new javax.swing.ImageIcon(getClass().getResource("/sys/picture/barcode.png")), jpVisualizarEtiqueta); // NOI18N

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        btnBuscar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find.png"))); // NOI18N
        btnBuscar.setText("BUSCAR");
        btnBuscar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });
        jPanel5.add(btnBuscar);

        btnSair.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/sair.png"))); // NOI18N
        btnSair.setText("SAIR");
        btnSair.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel5.add(btnSair);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(tabbedPane)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPane)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txProdutoActionPerformed
        if (validaInfo()) {
            buscaProduto();
        }
    }//GEN-LAST:event_txProdutoActionPerformed

    private void jcbPesIncrementalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPesIncrementalActionPerformed
        jcbPesContenha.setSelected(false);
    }//GEN-LAST:event_jcbPesIncrementalActionPerformed

    private void jcbPesContenhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPesContenhaActionPerformed
        jcbPesIncremental.setSelected(false);
    }//GEN-LAST:event_jcbPesContenhaActionPerformed

    private void btnMaiorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMaiorActionPerformed

        if (tabelaPesquisa.getRowCount() <= 0) {
            Mensagens.msgAtencao("selecione pelo menos 1 registro");
        } else {
            addProduto();
            atualizaTabelaEtiquetas();
        }
    }//GEN-LAST:event_btnMaiorActionPerformed

    private void btnMenor1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMenor1ActionPerformed

        if (tabelaListaEtiquetas.getRowCount() <= 0) {
            Mensagens.msgAtencao("é necessário ter pelo menos 1 registro para gerar etiquetas");
        } else {

            final BarraProgresso pb = new BarraProgresso(this);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    pb.gerarJanela();
                    pb.lbDescricao.setText("GERANDO, POR FAVOR AGUARDE...");
                    gerarEtiquetas();
                    return null;
                }

                @Override
                protected void done() {
                    pb.fechar();
                }
            };
            worker.execute();
        }

    }//GEN-LAST:event_btnMenor1ActionPerformed

    private void btnMenorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMenorActionPerformed

        if (listaTabelaEtiquetas.isEmpty()) {
            Mensagens.msgAtencao("selecione pelo menos 1 registro");
        } else {
            removerProduto();
        }
    }//GEN-LAST:event_btnMenorActionPerformed

    private void btnLimpaTabelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpaTabelaActionPerformed

        if (Mensagens.confirmar(this, " limpar tabela de etiquetas")) {
            listaTabelaEtiquetas.clear();
            atualizaTabelaEtiquetas();
        }
    }//GEN-LAST:event_btnLimpaTabelaActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed

        if (validaInfo()) {
            buscaProduto();
        }
    }//GEN-LAST:event_btnBuscarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnLimpaTabela;
    private javax.swing.JButton btnMaior;
    private javax.swing.JButton btnMenor;
    private javax.swing.JButton btnMenor1;
    private javax.swing.JButton btnSair;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JCheckBox jcbPesContenha;
    private javax.swing.JCheckBox jcbPesIncremental;
    private javax.swing.JPanel jpVisualizarEtiqueta;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JTable tabelaListaEtiquetas;
    private javax.swing.JTable tabelaPesquisa;
    private javax.swing.JTextField txProduto;
    // End of variables declaration//GEN-END:variables
}
